package priotityqeue;
import java.util.Comparator;
import java.util.PriorityQueue;
class Student{
    public int id;
    public String name;
    public int score;

    public Student(int id, String name, int score) {
        this.id = id;
        this.name = name;
        this.score = score;
    }

    @Override
    public String toString() {
        return "Student{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", score=" + score +
                '}';
    }
}
public class Test3 {
    public static void main(String[] args) {
        PriorityQueue<Student> pq = new PriorityQueue<>(new Comparator<Student>(){
            @Override
            public int compare(Student o1, Student o2) {
                return o2.score - o1.score;
            }
        });
        //此处没有设优先级，程序运行会出错，当我设置优先级后，程序运行正常。
        pq.offer(new Student(1, "Alice", 80));
        pq.offer(new Student(2, "Bob", 90));
        pq.offer(new Student(3, "Charlie", 70));
        pq.offer(new Student(4, "David", 60));
        System.out.println(pq.poll());
        System.out.println(pq.poll());
        System.out.println(pq.poll());
        System.out.println(pq.poll());

    }
}
